@using Umbraco.Cms.Core.Models.PublishedContent
@using Umbraco.Cms.Core.PublishedCache
@using Umbraco.Cms.Core.Routing
@using Umbraco.Cms.Core.Services.Navigation
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
@inject IVariationContextAccessor VariationContextAccessor
@inject IPublishedContentCache PublishedContentCache
@inject IDocumentNavigationQueryService DocumentNavigationQueryService
@inject IPublishedValueFallback PublishedValueFallback
@inject IPublishedUrlProvider PublishedUrlProvider
@*
    This snippet makes a list of links to the of children of the current page using an unordered HTML list.

    How it works:
    - It uses the Children method to get all child pages
    - It then uses the OrderByDescending() method, which takes the property to sort. In this case the page's creation date.
    - It then generates links so the visitor can go to each page
*@

@{ var selection = Model?.Content.Children(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService).Where(x => x.IsVisible(PublishedValueFallback)).OrderByDescending(x => x.CreateDate).ToArray(); }

@if (selection?.Length > 0)
{
    <ul>
        @foreach (var item in selection)
        {
            <li><a href="@item.Url(PublishedUrlProvider)">@item.Name</a></li>
        }
    </ul>
}
